<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Memory Manager - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.memory.memory-manager.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.memory.memory-manager.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.memory.overview.html">Overview</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.memory.html">Zend_Memory</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.memory.memory-objects.html">Memory Objects</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.memory.memory-manager" class="section"><div class="info"><h1 class="title">Memory Manager</h1></div>
    

    <div class="section" id="zend.memory.memory-manager.creation"><div class="info"><h1 class="title">Creating a Memory Manager</h1></div>
        

        <p class="para">
            You can create new a memory manager
            (<span class="classname">Zend_Memory_Manager</span> object) using the
             <span class="methodname">Zend_Memory::factory($backendName [, $backendOprions])</span>
            method.
        </p>

        <p class="para">
            The first argument <var class="varname">$backendName</var> is a string that
            names one of the backend implementations supported by <span class="classname">Zend_Cache</span>.
        </p>

        <p class="para">
            The second argument <var class="varname">$backendOptions</var> is an optional
            backend options array.
        </p>

        <pre class="programlisting brush: php">
$backendOptions = array(
    &#039;cache_dir&#039; =&gt; &#039;./tmp/&#039; // Directory where to put the swapped memory blocks
);

$memoryManager = Zend_Memory::factory(&#039;File&#039;, $backendOptions);
</pre>


        <p class="para">
            <span class="classname">Zend_Memory</span> uses <a href="zend.cache.backends.html" class="link"><span class="classname">Zend_Cache backends</span></a> as
            storage providers.
        </p>

        <p class="para">
            You may use the special name &#039;None&#039; as a backend name,
            in addition to standard <span class="classname">Zend_Cache</span> backends.
        </p>

        <pre class="programlisting brush: php">
$memoryManager = Zend_Memory::factory(&#039;None&#039;);
</pre>


        <p class="para">
            If you use &#039;None&#039; as the backend name, then the memory
            manager never swaps memory blocks. This is useful if you know that
            memory is not limited or the overall size of objects never reaches
            the memory limit.
        </p>

        <p class="para">
            The &#039;None&#039; backend doesn&#039;t need any option specified.
        </p>
    </div>

    <div class="section" id="zend.memory.memory-manager.objects-management"><div class="info"><h1 class="title">Managing Memory Objects</h1></div>
        

        <p class="para">
            This section describes creating and destroying objects in the
            managed memory, and settings to control memory manager behavior.
        </p>

        <div class="section" id="zend.memory.memory-manager.objects-management.movable"><div class="info"><h1 class="title">Creating Movable Objects</h1></div>
            

            <p class="para">
                Create movable objects (objects, which may be swapped) using
                the  <span class="methodname">Zend_Memory_Manager::create([$data])</span> method:
            </p>

            <pre class="programlisting brush: php">
$memObject = $memoryManager-&gt;create($data);
</pre>


            <p class="para">
                The <var class="varname">$data</var> argument is optional and used to
                initialize the object value. If the <var class="varname">$data</var>
                argument is omitted, the value is an empty string.
            </p>
        </div>

        <div class="section" id="zend.memory.memory-manager.objects-management.locked"><div class="info"><h1 class="title">Creating Locked Objects</h1></div>
            

            <p class="para">
                Create locked objects (objects, which are not swapped) using
                the  <span class="methodname">Zend_Memory_Manager::createLocked([$data])</span> method:
            </p>

            <pre class="programlisting brush: php">
$memObject = $memoryManager-&gt;createLocked($data);
</pre>


            <p class="para">
                The <var class="varname">$data</var> argument is optional and used to
                initialize the object value. If the <var class="varname">$data</var>
                argument is omitted, the value is an empty string.
            </p>
        </div>

        <div class="section" id="zend.memory.memory-manager.objects-management.destruction"><div class="info"><h1 class="title">Destroying Objects</h1></div>
            

            <p class="para">
                Memory objects are automatically destroyed and removed from
                memory when they go out of scope:
            </p>

            <pre class="programlisting brush: php">
function foo()
{
    global $memoryManager, $memList;

    ...

    $memObject1 = $memoryManager-&gt;create($data1);
    $memObject2 = $memoryManager-&gt;create($data2);
    $memObject3 = $memoryManager-&gt;create($data3);

    ...

    $memList[] = $memObject3;

    ...

    unset($memObject2); // $memObject2 is destroyed here

    ...
    // $memObject1 is destroyed here
    // but $memObject3 object is still referenced by $memList
    // and is not destroyed
}
</pre>


            <p class="para">
                This applies to both movable and locked objects.
            </p>
        </div>
    </div>

    <div class="section" id="zend.memory.memory-manager.settings"><div class="info"><h1 class="title">Memory Manager Settings</h1></div>
        

        <div class="section" id="zend.memory.memory-manager.settings.memory-limit"><div class="info"><h1 class="title">Memory Limit</h1></div>
            

            <p class="para">
                Memory limit is a number of bytes allowed to be used by loaded
                movable objects.
            </p>

            <p class="para">
                If loading or creation of an object causes memory usage to
                exceed of this limit, then the memory manager swaps some other
                objects.
            </p>

            <p class="para">
                You can retrieve or set the memory limit setting using the
                 <span class="methodname">getMemoryLimit()</span> and
                 <span class="methodname">setMemoryLimit($newLimit)</span> methods:
            </p>

            <pre class="programlisting brush: php">
$oldLimit = $memoryManager-&gt;getMemoryLimit();  // Get memory limit in bytes
$memoryManager-&gt;setMemoryLimit($newLimit);     // Set memory limit in bytes
</pre>


            <p class="para">
                A negative value for memory limit means &#039;no limit&#039;.
            </p>

            <p class="para">
                The default value is two-thirds of the value of
                &#039;memory_limit&#039; in php.ini or &#039;no limit&#039; (-1)
                if &#039;memory_limit&#039; is not set in php.ini.
            </p>
        </div>

        <div class="section" id="zend.memory.memory-manager.settings.min-size"><div class="info"><h1 class="title">MinSize</h1></div>
            

            <p class="para">
                MinSize is a minimal size of memory objects, which may be
                swapped by memory manager. The memory manager does not swap
                objects that are smaller than this value. This reduces the
                number of swap/load operations.
            </p>

            <p class="para">
                You can retrieve or set the minimum size using the
                 <span class="methodname">getMinSize()</span> and
                 <span class="methodname">setMinSize($newSize)</span> methods:
            </p>

            <pre class="programlisting brush: php">
$oldMinSize = $memoryManager-&gt;getMinSize();  // Get MinSize in bytes
$memoryManager-&gt;setMinSize($newSize);        // Set MinSize limit in bytes
</pre>


            <p class="para">
                The default minimum size value is 16KB (16384 bytes).
            </p>
        </div>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.memory.overview.html">Overview</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.memory.html">Zend_Memory</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.memory.memory-objects.html">Memory Objects</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.memory.html">Zend_Memory</a></li>
  <li><a href="zend.memory.overview.html">Overview</a></li>
  <li class="active"><a href="zend.memory.memory-manager.html">Memory Manager</a></li>
  <li><a href="zend.memory.memory-objects.html">Memory Objects</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>